import _ from 'lodash';
import { resetProjectData, resetCityData, resetPromiseOrAbilityData } from './constant';
import * as apis from '@/services/ReportMgr';

// 项目回款系数分析表
export const getProjectData = async ({ versionType, vsVersionType, yearMonth }, searchValue) => {
  const res = await apis.dmProjectReturnCoefficientUsingGET({
    // const res = await createData({
    params: {
      versionType,
      vsVersionType,
      yearMonth,
    },
  });
  let data = [];
  if (res && res.code === 1) {
    const newFilterData = _.filter(res.data, x => {
      if (x?.projectName?.includes(searchValue) || searchValue === '') return true;
      return false;
    });
    data = resetProjectData(newFilterData, {
      versionType,
      vsVersionType,
    });
  }

  return data;
};

// 城市回款系数分析表
export const getCityData = async ({ yearMonth }, searchValue) => {
  const res = await apis.dmCityReturnCoefficientUsingGET({
    // const res = await createData2({
    params: {
      yearMonth,
    },
  });
  let data = [];
  if (res && res.code === 1) {
    const newFilterData = _.filter(res.data, x => {
      if (x?.cityName?.includes(searchValue) || searchValue === '') return true;
      return false;
    });
    data = resetCityData(newFilterData);
  }
  return data;
};

// 项目回款系数分析表(承诺，能力)
export const getPromiseOrAbilityData = async ({ versionType, vsVersionType, yearMonth }) => {
  const res = await apis.dmInvestmentReturnUsingGET({
    params: {
      versionType,
      vsVersionType,
      yearMonth,
    },
  });
  if (!res || res.code !== 1) return res;
  const data = resetPromiseOrAbilityData(res.data, {
    versionType,
    vsVersionType,
    yearMonth,
  });
  return data;
};
